import 'package:flutter/material.dart';
import '../base_function.dart';

///@description:View 基类
abstract class BaseState<T extends StatefulWidget> extends State<T>
    with AutomaticKeepAliveClientMixin, BaseFunction {
  @override
  bool get wantKeepAlive => false;

  @override
  void initState() {
    initBaseCommon(this, context);
    buildCreate();
    super.initState();
  }

  @override
  // ignore: must_call_super
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        resizeToAvoidBottomInset: false,
        ///实现点击空白区域隐藏键盘
        body: GestureDetector(
          onTap: () {
            hideKeyboard();
          },
          child: getBaseView(context),
        ),
      ),
    );
  }

  Widget getBaseView(BuildContext context) {
    return Column(
      children: <Widget>[
        getBaseTopBar(),
        getBaseAppBar(),
        Container(
          width: getScreenWidth(),
          height: getMainWidgetHeight(),
          color: backgroundColor, //背景颜色，可自己变更
          child: buildWidget(context),
        ),
      ],
    );
  }

  Widget buildWidget(BuildContext context);

  //TODO:隐藏键盘
  void hideKeyboard() {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus?.unfocus();
    }
  }

  @override
  void buildCreate();

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
}
